import urllib2
import urllib
import simplejson as json
from content.contprov.general_classes import OneLink, clean_text, compose_search_param

def ask_digg(keywords):
	links = []
	url = 'http://services.digg.com/2.0/search.search?query='
	search = compose_search_param(keywords)
	for s in search:
		fulurl = url+s
		response = urllib2.urlopen(fulurl)
		try:
			requestJson = json.loads(response.read())
		except ValueError:
			raise Http404
		for one in requestJson['stories']:
			duck = OneLink(url=one['link'], description=clean_text(one['description']))
			links.append(duck)
	return links
